package cn.tedu.boot.demo.controller;

import cn.tedu.boot.demo.dto.AdminAddNewDTO;
import cn.tedu.boot.demo.entity.Admin;
import cn.tedu.boot.demo.service.IAdminService;
import cn.tedu.boot.demo.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "1. 管理员模块")
@Slf4j
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService adminService;
    //排序
    @ApiOperationSupport(order = 10)
    @ApiOperation("增加管理员")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid AdminAddNewDTO adminAddNewDTO){
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();

    }
    @ApiOperation("根据id查询管理员详情")
    @ApiImplicitParam(name="id",value = "管理员id",example = "1",required = true,dataType = "long")
    @ApiOperationSupport(order = 40)
     @GetMapping("/{id:[0-9]+}")
    @PreAuthorize("hasAuthority('/ams/admin/read')") // 要求权限中具有 /ams/admin/read 这一条才允许访问此资源
    public JsonResult<Admin> getById(@PathVariable Long id){
        throw new RuntimeException("此功能尚未实现");
    }

    @ApiOperationSupport(order = 41)
    @ApiOperation("根据角色类型查询管理员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="roleId",value = "角色id",example = "1",
                    required = true, dataType = "long"),
            @ApiImplicitParam(name = " page",value = "页码",example = "1",required = false,dataType = "int")
    })
    @GetMapping("/list-by-role")
    public JsonResult<Admin> listByRole(Long roleId,Integer page){
        throw new RuntimeException("此功能尚未实现");
    }
}
